﻿using System.Web;
using System.Text;
using System.IO;
using System.Net;
using System;
using System.Xml;
using System.Collections.Generic;
using NetCoreCMS.Common;
using Microsoft.AspNetCore.Http;

namespace NetCoreCMS.PayAPI.chinabankpc
{
    public class Config
    {
        #region 字段
        private string partner = string.Empty;
        private string key = string.Empty;
        private string return_url = string.Empty;
        private string notify_url = string.Empty;
        private string input_charset = string.Empty;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model">站点支付方式</param>
        /// <param name="payModel">支付平台</param>
        /// <param name="sysConfig">系统配置</param>
        /// <param name="context"></param>
        public Config(Models.Site_payment model, Models.Payment payModel, Models.Sysconfig sysConfig, HttpContext context)
        {
            if (model != null)
            {
                partner = model.key1; //商户号（必须配置）
                key = model.key2; //商户支付密钥，参考开户邮件设置（必须配置）
                //回调处理地址
                if (!string.IsNullOrEmpty(sysConfig.weburl)) //如果有自定义域名
                {
                    return_url = sysConfig.weburl + payModel.return_url;
                    notify_url = sysConfig.weburl + payModel.notify_url;
                }
                else //否则使用当前域名
                {
                    return_url = context.Request.Scheme+"://" + context.Request.Host.Host.ToLower() + payModel.return_url;
                    notify_url = context.Request.Scheme + "://" + context.Request.Host.Host.ToLower() + payModel.notify_url;
                }
                input_charset = "utf-8";
            }
        }

        #region 属性
        /// <summary>
        /// 商户编号
        /// </summary>
        public string Partner
        {
            get { return partner; }
            set { partner = value; }
        }

        /// <summary>
        /// 获取或设置交易安全检验码
        /// </summary>
        public string Key
        {
            get { return key; }
            set { key = value; }
        }

        /// <summary>
        /// 获取页面跳转同步通知页面路径
        /// </summary>
        public string Return_url
        {
            get { return return_url; }
        }

        /// <summary>
        /// 获取服务器异步通知页面路径
        /// </summary>
        public string Notify_url
        {
            get { return notify_url; }
        }

        /// <summary>
        /// 获取字符编码格式
        /// </summary>
        public string Input_charset
        {
            get { return input_charset; }
        }
        #endregion
    }
}
